import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src'),
    },
  },
  server: {
    port: 3000,
    proxy: {
      '/api': {
        target: 'http://192.168.0.100:8080',
        changeOrigin: true,
        rewrite: (path) => path.replace(/^\/api/, '')
      },
      // 单独配置文件下载路径，不经过前端路由
      '/file/download': {
        target: 'http://192.168.0.100:8080',
        changeOrigin: true
      },
      '/ws': {
        target: 'ws://192.168.0.100:8080',
        ws: true
      }
    }
  },
  build: {
    // 启用CSS代码分割
    cssCodeSplit: true,
    // 启用源映射
    sourcemap: false,
    // 禁用brotliSize显示
    brotliSize: false,
    // 启用最小化混淆
    minify: 'terser',
    // 分割包策略
    rollupOptions: {
      output: {
        manualChunks: {
          // 将ElementPlus、Vue等大型库单独打包
          'element-plus': ['element-plus'],
          'vue': ['vue', 'vue-router', 'pinia'],
        }
      }
    },
    // Terser配置
    terserOptions: {
      compress: {
        // 生产环境移除console
        drop_console: true,
        drop_debugger: true
      }
    },
    // 设置块大小警告的限制
    chunkSizeWarningLimit: 800
  }
}) 